<?php
# author: tran ngoc thang
# email : tranngocthang89@gmail.com
# desc: dùng lưu trữ các hàm dùng chung trong website
App::uses('Component', 'Controller');
class CommComponent extends Component {

    var $_controller = null;
    static $_nameController = "Users";
    public function __construct()
    {
        # code...
    }
    // public function startup(Controller $controller){
    //     $this::$_controller = $controller;
    //     $this::$_controller->set('app', new CommComponent());
    // }
    // saving the controller reference for later use
    public function initialize(Controller $controller, $settings = array()) {
        //$this->_controller = $controller;
        //$this->_controller->set('app', new CommComponent());
    }
    //called after Controller::beforeFilter()
    public function startup(Controller $controller) {
        $this->_controller = $controller;
        $this::$_nameController = $controller->name;
        $this->_controller->set('app', new CommComponent());
    }
    //called after Controller::beforeRender()
    public function beforeRender(Controller $controller) {}
    //called after Controller::render()
    public function shutdown(Controller $controller) {}
    //called before Controller::redirect()
    public function beforeRedirect(Controller $controller, $url, $status=null, $exit=true) {}
    public function test()
    {
       echo "ok";
    }
    //hàm chuyển trạng thái
    //input: 0-1
    //output: 1-0
    // public function toggle($id,$stt,$s = 'status'){
    //     $obj = $this::$_nameController;
    //     $modelName = $this->singularize($obj);
    //     if(isset($id)){
    //         $model = ClassRegistry::init($modelName);
    //        // $model->layout = false;
    //         //$model->autoRender = false;
    //         $model->id = $id;
    //         $model->saveField($s,$stt);
    //     }
    // }
}